import java.util.Arrays;


public class SearchForARange {
	public void tester() {
		int [] a = {2,2};
		int [] re = searchRange(a, 1);
		System.out.println(Arrays.toString(re));
	}
	public int[] searchRange(int[] A, int target) {
        int a = bsLeft(A, target);
        int b = bsRight(A, target);
        
        int [] re = {a, b};
        return re;
    }
    
    public int bsLeft(int [] array, int t) {
        int a = 0, b = array.length-1, mid = -1;
        
        while(a < b) {
        	System.out.println(a+" "+b);
            mid = (a+b)/2;
            if(array[mid] < t) a = mid+1;
            else if(array[mid] > t) b = mid-1;
            else b = mid;
        }
        if(b>=0 && array[b] == t) return b;
        return -1;
    }
    
    public int bsRight(int [] array, int t) {
        int a = 0, b = array.length-1, mid = -1;
        
        while(a < b) {
            mid = (a+b)/2;
            if(mid == a) mid = b;
            if(array[mid] < t) a = mid+1;
            else if(array[mid] > t) b = mid-1;
            else a = mid;
        }
        if(array[a] == t) return a;
        return -1;
    }
}